// 数组解构

const arr  = [100, 200, 300]

// const [foo, bar, baz] = arr 
// console.log(foo, bar, baz)

// const [, bar, baz] = arr 
// console.log(bar, baz)

const [...rest] = arr
console.log(rest)


const path = '/foo/a/b'
const [, rootdir] = path.split('/')
console.log(rootdir)



// 对象解构
const obj = {
    name: 'congyang',
    age: 18
}

const { 
    name: objName,
    age,
    sex = 'femal'
} = obj
console.log(age)
console.log(sex) // 可以赋默认值
console.log(objName) // name冒号后面的是赋值的变量名称

// 对象解构的应用场景
const { log } = console
log('header') 
log('footer') 


